<?php
class ajaxcall extends Controller
{
	function __constructor()
	{
		parent::__constructor();
	}
	
	function worklog_getjobs()
	{
		is_logged_in();
		
		$this->load->model("model_job");
		$company_id = $this->input->post("company_id");
		$jobs = $this->model_job->getJobs(99999, array("job.created", "desc"), $where = array("company_id" => $company_id));
		
		$jobs_array = "";
		
		foreach($jobs as $job)
		{
			
			$jobs_array .= "<option value='".$job['id']."'>#" . $job['id'] ." - " .word_limiter($job['job_subject'],5) . "</option>";
		}
		echo json_encode($jobs_array);
	}
	
	function job_delete()
	{
		$this->load->model("model_job");
		$id = $this->input->post("id");
		if($id != "")
		{
			$this->model_job->updateJob(array("active"=>0), $id);
		}
		echo json_encode(true);
	}

	function client_delete()
	{
		$this->load->model("model_company");
		$id = $this->input->post("id");
		if($id != "")
		{
			$this->model_company->removeCompany($id);
		}
		echo json_encode(true);
	}
	
	function user_delete()
	{
		$this->load->model("model_user");
		$id = $this->input->post("id");
		if($id != "")
		{
			$this->model_user->removeUser($id);
		}
		echo json_encode(true);
	}
	
	function job_invoiced()
	{
		$this->load->model("model_job");
		$id = $this->input->post("id");
		$status = $this->input->post("status");	
		if($id != "")
		{
			$this->model_job->invoiced($status, $id);
		}
		//echo json_encode(true);
	}
}
